<template>
  <div id="app">
    <el-container>
      <el-header v-if="userStore.user.id" height="60px">
        <el-menu mode="horizontal" :ellipsis="false" router>
          <el-menu-item index="/home">首页</el-menu-item>
          <el-menu-item index="/add-course">添加课程</el-menu-item>
          <el-menu-item index="/add-category">添加分类</el-menu-item>
          <div style="flex: 1"></div>
          <el-menu-item @click="handleLogout">
            <el-icon><User /></el-icon>
            {{ userStore.user.username }} - 退出
          </el-menu-item>
        </el-menu>
      </el-header>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { User } from '@element-plus/icons-vue'
import { useUserStore } from './stores/user'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const router = useRouter()

const handleLogout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.el-header {
  background-color: #545c64;
  color: #fff;
  padding: 0;
}

.el-main {
  padding: 20px;
}
</style>